package TextEditor.facade;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
/**
 * Implementation of FileInterface to search the text
 */
public class SearchOpertion implements FileInterface {

	private String pattern = "";
	boolean isDownWard = true ;
	boolean isMarchCase = false ;
	
	SearchOpertion(String pattern){ //boolean isDownWard, boolean isMarchCase

		this.pattern = pattern;
	}
	
	@Override
	public void fileOperation(JTextArea textArea) {
		
		int head = 0, tail = 0, current =0;
		
		String contents = textArea.getText().toLowerCase();
		pattern = pattern.toLowerCase();
		head = textArea.getCaretPosition();
		
		int index = contents.indexOf(pattern, head)	;	
		if (index != -1){
			
			textArea.select(index, index + pattern.length());
			head = pattern.length()+ 1;
			textArea.setCaretPosition(head);
			
		}
		else {
			JOptionPane.showMessageDialog(textArea,"Can find String:  "+ pattern ,"Information",JOptionPane.INFORMATION_MESSAGE);
		}
		
	}

}
